package com.example.pt.config;

import com.example.pt.interceptor.JWTInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC配置类
 * 用于注册拦截器和配置拦截规则
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private JWTInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册JWT拦截器
        registry.addInterceptor(jwtInterceptor)
                // 暂时放行所有请求
                .excludePathPatterns("/**")
                .excludePathPatterns("/api/user/seed-stats/update-all")
                .excludePathPatterns("/api/user/level/update-all")
                // 放行登录接口
                .excludePathPatterns("/login/**")
                // 放行登录接口
                //.excludePathPatterns("/**")
                .excludePathPatterns("/status/**")
                // 放行注册接口
                .excludePathPatterns("/register/**")
                .excludePathPatterns("/api/torrent/**")
                .excludePathPatterns("/api/tracker/**")
                // 暂时放行用户相关接口
                //.excludePathPatterns("/api/users/**")
                //暂时放行评论api
                //.excludePathPatterns("/api/comments/**")
                // 放行错误页面
                .excludePathPatterns("/error")
                //.excludePathPatterns(HttpMethod.OPTIONS.name())
                // 放行下载接口
                .excludePathPatterns("/download");
        //暂时放行评论api
        //.excludePathPatterns("/api/comments/**")
    }
} 